const { sequelize } = require('../utils/database');
const { 
  User, 
  UserProfile, 
  Activity, 
  Badge, 
  Feed, 
  CheckIn, 
  ActivityParticipant,
  UserFollow,
  FeedLike,
  FeedComment
} = require('../models');

async function syncDatabase() {
  try {
    console.log('开始同步数据库...');
    
    // 同步所有模型，包括新增的表
    await sequelize.sync({ alter: true });
    
    console.log('数据库同步完成！');
    console.log('所有表已创建或更新：');
    console.log('- users');
    console.log('- user_profiles');
    console.log('- activities');
    console.log('- badges');
    console.log('- feeds');
    console.log('- check_ins');
    console.log('- activity_participants');
    console.log('- user_follows (新增)');
    console.log('- feed_likes (新增)');
    console.log('- feed_comments (新增)');
    
  } catch (error) {
    console.error('数据库同步失败:', error);
    throw error;
  }
}

// 如果直接运行此脚本
if (require.main === module) {
  syncDatabase()
    .then(() => {
      console.log('数据库同步脚本执行完成');
      process.exit(0);
    })
    .catch(error => {
      console.error('数据库同步脚本执行失败:', error);
      process.exit(1);
    });
}

module.exports = { syncDatabase }; 